# agents/factor_agents/aglaea_agent.py
from .base_factor_agent import BaseFactorAgent
from game_engine.game_state import FactorDevelopment, GameWorld
import numpy as np

class AglaeaAgent(BaseFactorAgent):
    """阿格莱雅智能体 - 高速召唤特化 [火种：浪漫]"""
    
    def __init__(self, factor: FactorDevelopment, game_world: GameWorld):
        super().__init__(factor, game_world)
        self.personality_traits.update({
            "aggression": 0.6,      # 中等攻击性
            "social": 0.7,          # 高社交性
            "summon_focus": 0.8,    # 召唤专注
            "romantic_ideals": 0.9  # 浪漫理想
        })
        self.summoned_allies = []
        self.last_summon_time = 0
    
    def make_decision(self, current_time: int) -> str:
        """阿格莱雅的决策逻辑"""
        situation = self.evaluate_situation()
        
        # 检查召唤物状态
        active_summons = len([s for s in self.summoned_allies if s["active"]])
        
        # 需要补充召唤物
        if active_summons < 2 and current_time - self.last_summon_time > 30:
            if self.should_use_special_ability():
                self.last_summon_time = current_time
                return "romantic_summon"
            else:
                return "prepare_summon"
        
        # 指挥召唤物攻击
        if active_summons > 0 and situation["nearby_threats"]:
            target = situation["nearby_threats"][0]
            return f"command_summons_attack:{target.name}"
        
        # 支援队友
        if situation["allies_need_help"]:
            most_needy = min(situation["allies_need_help"], 
                           key=lambda x: x.attributes['health'])
            return f"support_ally:{most_needy.name}"
        
        # 提升召唤能力
        return "train_summoning"
    
    def evaluate_situation(self) -> Dict:
        """评估当前局势"""
        nearby_factors = self.get_nearby_factors()
        
        threats = [f for f in nearby_factors if self._is_potential_threat(f)]
        allies_need_help = [f for f in nearby_factors 
                          if f.attributes['health'] < f.attributes['health'] * 0.6]
        
        return {
            "nearby_threats": threats,
            "allies_need_help": allies_need_help,
            "active_summons": len([s for s in self.summoned_allies if s["active"]]),
            "summon_cooldown": max(0, 30 - (self.game_world.current_time - self.last_summon_time))
        }
    
    def update_summon_status(self):
        """更新召唤物状态"""
        for summon in self.summoned_allies:
            if summon["active"] and self.game_world.current_time - summon["summon_time"] > 60:
                summon["active"] = False